<template>
  <!-- 主页的布局 -->
  <el-container height="100%">
    <!-- 头部信息 -->
    <el-header height="15%">
      <span class="title_span">千锋在线教育平台 - 教师端</span>
      <div style="display: flex; flex-direction: row; justify-content: center; align-items: center;">
        <div style="display: flex; flex-direction: column; justify-content: center; align-items: center;">
          <!-- 头像 -->
          <img style="width: 60px; height: 60px; border-radius: 30px; background-color: #E9EEF3;" :src="user.header"/>
          <span style="font-size: 15px; color: white; margin-top: 10px;">{{user.name}}</span>
        </div>

        <el-button type="warning" style="margin-left: 20px;" @click="logout">注销</el-button>
      </div>
    </el-header>
    <el-container style="height: 75%;">
      <!-- 左侧菜单栏 -->
      <el-aside width="200px">
        <el-menu
          default-active="2"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b">
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>课程管理</span>
            </template>
            <el-menu-item index="1-1" @click="goPage('/CourseTypeManager')">分类管理</el-menu-item>
            <el-menu-item index="1-2" @click="goPage('/PublishCourse')">发布课程</el-menu-item>
            <el-menu-item index="1-3"  @click="goPage('/CourseManager')">我的课程</el-menu-item>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-s-custom"></i>
              <span>个人中心</span>
            </template>
            <el-menu-item index="2-1" @click="goPage('/InfoManager')">我的信息</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 工作区 -->
      <el-main>
        <!-- 这是一个路由组件 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  export default {
    data(){
      return {
        user: {
          header: "../../static/logo.png",
          name: "昵称"
        }
      }
    },
    methods: {
      //进行页面跳转
      goPage(url){
        this.$router.push(url);
      },
      //注销
      logout(){
        //删除本地的令牌
        this.$.removeToken();
        //跳转到登录页
        this.$router.push("/");
      }
    },
    mounted(){
      //获取用户信息
      var user = this.$.parseJwtToken();
      if(!user){
        //跳转到登录页
        this.$router.push("/");
        return;
      }

      //获取用户的基本信息
      if(user.header){
        this.user.header = this.$.getImgUrl(user.header);
      }
      this.user.name = user.name;
    }
  }
</script>

<style scoped>
    .el-container {
      height: 100%;
    }

   .el-header {
      background-color: #2C3E50;
      color: #333;
      text-align: center;
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: space-between;
    }

    .el-aside {
      background-color: #545c64;
      color: #333;
      text-align: center;
    }

    .el-main {
      background-color: white;
      color: #333;
      text-align: center;
      padding: 0px;
    }

    .title_span {
      color: white;
      font-size: 30px;
      font-family: "楷体";
      text-shadow: 5px 5px 5px whitesmoke;
    }

    .el-menu {
      border: none !important;
    }

</style>
